package com.cow.support.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cow.framework.core.base.BaseComponent;
import com.cow.support.dao.ResourceDAO;
import com.cow.support.entity.Resourceinfo;

@Service
public class ResourceService extends BaseComponent{
	@Autowired
	private ResourceDAO resourceDAO;

	public void setResourceDAO(ResourceDAO resourceDAO) {
		this.resourceDAO = resourceDAO;
	}
	public HashMap<String, List<Resourceinfo>> getUserResource(Integer userID, String systemID) {
		HashMap<String, List<Resourceinfo>> map = new HashMap<String, List<Resourceinfo>>();
		List<Resourceinfo> resourceList = resourceDAO.getUserResource(userID, systemID);
		for (Resourceinfo resourceinfo : resourceList) {
			List<Resourceinfo> singleTypeList = map.get(resourceinfo.getResourcetype());
			if (singleTypeList == null) {
				singleTypeList = new ArrayList<Resourceinfo>();
				map.put(resourceinfo.getResourcetype(), singleTypeList);
			}
			singleTypeList.add(resourceinfo);
		}

		return map;
	}
	
	public List<Resourceinfo> findBySystemidAndResourcetype(String systemID,String resourceType){
		return resourceDAO.findBySystemidAndResourcetype(systemID, resourceType);
	}
}
